package be.vdab;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import be.vdab.dao.NamenDAOException;
import be.vdab.services.NamenService;

public class Main {
	  public static void main(String[] args) {
	    /*try (ClassPathXmlApplicationContext context = 
	        new ClassPathXmlApplicationContext("spring/container.xml")){
	    	ClassA objectA = context.getBean(ClassA.class);
	    	System.out.println(objectA.getBoodschap());
	    	System.out.println(objectA.getTelefoonNrHelpDesk());
	    	System.out.println(objectA.getAantalPogingenUpdateKlant());
	    	try {
	    	  System.out.println(objectA.getUrlKoersenVreemdeMuntenTOVEuro().getHost());
	    	} catch (Exception ex) { // getHost() kan exception werpen
	    	  ex.printStackTrace();
	    	}
	    	System.out.println(
	    	  objectA.getDefaultTaalEnLandVanDeApplicatie().getDisplayName());
	    	System.out.print("Importbestand bestaat");
	    	 if ( ! objectA.getBestandMetTeImporterenData().exists()) { 
	    	  System.out.print(" niet");
	    	}
	    	System.out.println();
	    	System.out.println(objectA.getMaxTemperatuurMotor());
	    	System.out.println(objectA.getStandaardBladRichtingInPrinter()); 
	    	ClassB objectB = context.getBean("classB", ClassB.class);
	    		    	
	    	System.out.println(objectB.getBoodschap());
	    	System.out.println(objectB.getTelefoonNrHelpDesk());
	    	System.out.println(objectB.getAantalPogingenUpdateKlant()); 
	    	HelpdeskMedewerkers medewerkers = context.getBean(HelpdeskMedewerkers.class);
	    	System.out.println(medewerkers);
	    	Scanner scanner = new Scanner(System.in);
	    	System.out.print("Naam:");
	    	String naam = scanner.nextLine();
	    	String telefoonNr = medewerkers.getInternTelefoonNr(naam);
	    	System.out.println(telefoonNr == null ? "Niet gevonden" : telefoonNr); 
	    }
	  }
		  System.out.println("Spring container configuratie begint.");
		  try (ClassPathXmlApplicationContext context = 
		    new ClassPathXmlApplicationContext("spring/container.xml")) {   
			  System.out.println("Spring container configuratie gedaan.");
		    Teller teller1 = context.getBean("teller1", Teller.class);
		    teller1.verhoogTeller();
		    System.out.println(teller1.getTeller());
		    System.out.println(context.getBean("teller1", Teller.class).getTeller());
		  }*/
		 
		  try (ClassPathXmlApplicationContext context = 
		    new ClassPathXmlApplicationContext("spring/dao.xml", "spring/services.xml", "spring/advice.xml")) {   	    
		    List<String> namen = new ArrayList<String>();
		    Scanner scanner = new Scanner(System.in);
		    System.out.println(
		    		"Tik de namen, gescheiden door Enter. Tik stop na de laatste naam");
		    for (String naam; ! "stop".equals(naam = scanner.nextLine()); ) {
		    	  namen.add(naam);
		    	}
		    NamenService namenService = context.getBean(NamenService.class);
		    System.out.println("main roept opslaan op");
		    try{
		    	namenService.opslaan(namen);
		    }catch(NamenDAOException ex){
		    	System.out.println("probleem bij opslaan"); 
		    }
		    System.out.println("terug in main");
		    System.out.println("main roept getAantalOpgeslagenNamen op");
		    try{
		    	int aantalNamen = namenService.getAantalOpgeslagenNamen();
		    	System.out.println("terug in main, aantal namen:" + aantalNamen);
		    }catch(NamenDAOException ex){
		    	System.out.println("Probleem bij lezen namen");
		    }
		  }
		 /* try (ClassPathXmlApplicationContext context = 
				    new ClassPathXmlApplicationContext("spring/container.xml")) { 
			  ClassA objectA = context.getBean(ClassA.class);
			  System.out.println(objectA.getWebMasterEMailAdres());
			  System.out.println(objectA.getWebsiteGestart());
		  }*/
		  /*try (ClassPathXmlApplicationContext context = 
				  new ClassPathXmlApplicationContext("spring/container.xml")) {
				  Spelletje spel = context.getBean(Spelletje.class);
				  System.out.println(spel.getAantalVijanden());
		  } */
		  
	  }
} 
